package zhklappoint.initsys;

import java.util.List;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import zhklappoint.ZhklAppointApplication;


@Configuration
public class MyWebMvcConfigurerAdapter implements WebMvcConfigurer {
    //关键，将拦截器作为bean写入配置中
    @Bean
    public WxApiInterceptors myAuthInterceptor() {
        return new WxApiInterceptors();
    }
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 把已经注入bean了的拦截器初始化
        InterceptorRegistration ir = registry.addInterceptor(myAuthInterceptor());
        //下面是需要拦截的路径
        ir.addPathPatterns("/uni/api/**");
        // 不拦截的路径可写下面
         ir.excludePathPatterns("**/eu5bwBYdDh.txt");
         ir.excludePathPatterns("**/sVixTYxdLs.txt");
        // 还可以注册其它的拦截器
        //registry.addInterceptor(new OtherInterceptor()).addPathPatterns("/**");
    }
    @Override
    public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
        argumentResolvers.add(loginArgumentResolver());
    }
    @Bean
    public LoginUserHandlerMethodArgumentResolver loginArgumentResolver() {
        return new LoginUserHandlerMethodArgumentResolver();
    }
}